function Desc()
{
	this.id = "";
	this.t = "";
	this.description = "";
	this.po = "";
	this.rb = "";
	this.tn = "";
	this.dl = "";
	this.pt = "";
	this.pk = "";
	this.er = "";
	this.ac = "";
}
var description = new Array();
function getTitle()
{
	init();
	for(var i = 0; i < descriptions.length; i++)
	{
		var title = document.getElementById("title"+i);
		title.innerHTML = descriptions[i].t;
		document.getElementById("ccc"+i).innerHTML += "<div class='more'><a href='javascript:openWindow("+descriptions[i].id +")'>More Details</a></div>";
	}
	setInterval("setRightClickMenu()",500);
}

function getTitle1()
{
	init();
	//getNews();
	for(var i = 0; i < descriptions.length; i++)
	{
		var title = document.getElementById("title"+i);
		title.innerHTML = descriptions[i].t;
		var out ="";
		if(usernameS == "null")
			document.getElementById("ccc"+i).innerHTML += "<div class='more'><a color='black' href='javascript:openWindow("+descriptions[i].id +")' >More Details</a></div>";
		else if(typeS == "student")
		{
			 out= "<div class='more'><a href='showProject.jsp?pId="+ descriptions[i].id +"'>More Details</a>&nbsp;&nbsp;&nbsp;";
			if(descriptions[i].stStatus == "pend")
				out += "<a href='deleteSProject.jsp?pId="+ descriptions[i].id +"'>Delete</a></div><div class='status'>&nbsp;&nbsp;&nbsp;"+descriptions[i].stStatus+"</div>";
			else
				out += "<div class='status'>&nbsp;&nbsp;&nbsp;"+descriptions[i].stStatus+"</div></div>";
			document.getElementById("ccc"+i).innerHTML += out;
		}
		else
			document.getElementById("ccc"+i).innerHTML += "<div class='more'><a href='showProject.jsp?pId="+ descriptions[i].id +"'>Display</a>&nbsp;&nbsp;&nbsp;<a href='editProject.jsp?pId="+ descriptions[i].id +"'>Edit</a></div><div class='status'>&nbsp;&nbsp;&nbsp;"+descriptions[i].status+"</div>";
	}
	setInterval("setRightClickMenu()",500);
}

function getNews()
{
	init2();
	news();
}

function createDiv(x)
{
	var td = document.getElementById("td"+x);
	original[x] = td.innerHTML;
	td.innerHTML += "<div id='content"+x+"' width='"+td.style.width+"' height='" + (td.style.height.substring(0,td.style.height.indexOf("p")) -20) + "'></div>";
}

function deleteDiv(x)
{
	var td = document.getElementById("td"+x);
	if(original[x] != null)
		td.innerHTML = original[x];
}

function mouse(x)
{
	if(!click[x])
	{
		var div = document.getElementById("td" + x);
		div.className = "over";
	}
}
function mouseo(x)
{
	if(!click[x])
	{
		var div = document.getElementById("td" + x);
		div.className = "normal";
	}
}
var intervald = new Array();
var intervalu = new Array();
var increment = new Array(0,0,0,0,0,0,0,0,0,0,0);
var original = new Array();
var click = new Array(false,false,false,false,false,false,false,false,false,false);
var pretd = new Array();
var appearance = new Array();
function clicked(x)
{
	var contentId = "td" + x;
        var div = document.getElementById(contentId);
	if(increment[x] % 2 == 0)
	{
		div.style.visibility = "visible";
		if(intervalu[x] != null)
			clearInterval(intervalu[x]);
		intervald[x] = setInterval("increaseHeight('"+x+"')",15);
		increment[x]++;
		div.className= "clicked";
		click[x] = true;
	}
	else
	{
		deleteDiv(x);
		if(intervald[x] != null)
			clearInterval(intervald[x]);
		intervalu[x] = setInterval("decreaseHeight('"+x+"')",15);
		increment[x]++;
		click[x] = false;
		div.className = "over";
	}
}

function increaseHeight(x)
{
	var div = document.getElementById("td"+x);
	var height = div.style.height.substring(0,div.style.height.indexOf("p"));
	height = height *1;
	if(height < 300)
	{
		div.style.height = Math.floor((height + (320-height)/7) )+ "px";
	}
	else
	{
		clearInterval(intervald[x]);
		intervald[x] = null;
		//appearance[x] = setInterval("appearse("+x+")",5);
		fillTabs(x);
	}
}

function decreaseHeight(x)
{
	var div = document.getElementById("td"+x);
	var height = div.style.height.substring(0,div.style.height.indexOf("p"));
	height = height *1;
	if(height > 0)
	{
		div.style.height = Math.floor((height - (height-20)/7) )+ "px";
	}
	else
	{
		clearInterval(intervalu[x]);
		intervalu[x] = null;

	}
}

var descriptions = new Array();
function fillTabs(x)
{
	createDiv(x);
	
	var div = document.getElementById("content"+x);
	var td = document.getElementById("td"+x);
	var tabsTiles = new Array("Title","description","project objectives");
	var out = "<iframe src='dragAssign.jsp?prjID="+descriptions[x].id+"' width='100%' height='"+ (td.style.height.substring(0,td.style.height.indexOf("p")) -20) +"'></iframe></table>";
	div.innerHTML = out;
}

function show(x,type)
{
	var tab = document.getElementById(type+x);
	if(tab.className == "free")
	{
		var div = document.getElementById("descBody"+x);
		div.innerHTML = "<br>&nbsp;&nbsp;&nbsp;" + eval("descriptions["+x+"]."+type);
		var td = document.getElementById(type+x);
		td.className = "choosen";
		if(pretd[x] != null)
			pretd[x].className = "free";
		pretd[x] = td;
		
	}
}

function appearse(x)
{
	var img = document.getElementById("img");
	var td = document.getElementById("td"+x);
	img.style.width = "985";
	img.style.height = td.style.height.substring(0,td.style.height.indexOf("p")) -21;
	img.style.top = 110;
	img.style.left = 260 ;
	if(img.filters)
	{
		if(img.filters.item(0).opacity > 0)
		{
			img.filters.item(0).opacity -=5;
			img.style.visibility = "visible";
			fillTabs(x);
		}
		else
		{
			img.style.visibility = "hidden";
			clearInterval(appearance[x]);
		}
	}
}

function reset()
{
	document.getElementById("id").innerHTML = "";
	document.getElementById("fname").innerHTML = "";
	document.getElementById("lastname").innerHTML = "";
	document.getElementById("username").innerHTML = "";
	document.getElementById("password").innerHTML = "";
	document.getElementById("repassword").innerHTML = "";
}

function checkData()
{
	reset();
	var dataError= false;
	if(document.addStudent.id.value.length != 7 || document.getElementById("idf").value.length != 7) {
		document.getElementById("id").innerHTML = "<font style='color: red; font-size: 9pt'>The ID must be 7 digits</font>";
		dataError = true;
	}
	if(document.addStudent.fname.value.length < 2 || document.getElementById("fnamef").value.length < 2 ) {
		document.getElementById("fname").innerHTML = "<font style='color: red; font-size: 9pt'>The first name must be at least 2 characters</font>";
		dataError = true;
	}
	if(document.addStudent.lastname.value.length < 2) {
		document.getElementById("lastname").innerHTML = "<font style='color: red; font-size: 9pt'>The last name must be at least 2 characters</font>";
		dataError = true;
	}
	if(document.addStudent.username.value.length < 2) {
		document.getElementById("username").innerHTML = "<font style='color: red; font-size: 9pt'>The username must be at least 2 characters</font>";
		dataError = true;
	}
	if(document.addStudent.password.value.length < 6) {
		document.getElementById("password").innerHTML = "<font style='color: red; font-size: 9pt'>The password must be at least 6 characters</font>";
		dataError = true;
	}
	if(document.addStudent.password.value != document.addStudent.repassword.value) {
		document.getElementById("repassword").innerHTML = "<font style='color: red; font-size: 8pt'>The password and re-password does not match</font>";
		dataError = true;
	}
	if(!dataError)
		document.addStudent.submit();
}


function resetP()
{
	document.getElementById("fname").innerHTML = "";
	document.getElementById("lastname").innerHTML = "";
	document.getElementById("email").innerHTML = "";
	document.getElementById("username").innerHTML = "";
	document.getElementById("password").innerHTML = "";
	document.getElementById("repassword").innerHTML = "";
}

function checkDataP()
{
	resetP();
	var check = true;
	if(document.addProfessor.fname.value.length < 2) {
		document.getElementById("fname").innerHTML = "<font style='color: red; font-size: 9pt'>The first name must be at least 2 characters</font>";
		check = false;
	}
	if(document.addProfessor.lastname.value.length < 2) {
		document.getElementById("lastname").innerHTML = "<font style='color: red; font-size: 9pt'>The last name must be at least 2 characters</font>";
		check = false;
	}
	if(document.addProfessor.username.value.length < 2) {
		document.getElementById("username").innerHTML = "<font style='color: red; font-size: 9pt'>The username must be at least 2 characters</font>";
		check = false;
	}
	if(document.addProfessor.password.value.length < 6) {
		document.getElementById("password").innerHTML = "<font style='color: red; font-size: 9pt'>The password must be at least 6 characters</font>";
		check = false;
	}
	if(document.addProfessor.password.value != document.addProfessor.repassword.value) {
		document.getElementById("repassword").innerHTML = "<font style='color: red; font-size: 8pt'>The password field and retype password does not match</font>";
		check = false;
	}
	if(document.addProfessor.email.value.length < 6) {
		document.getElementById("email").innerHTML = "<font style='color: red; font-size: 9pt'>The Email must be at least 6 characters</font>";
		check = false;
	}
	if(!check)
		document.addProfessor.submit();
}

function assign(x,i)
{
	var dist = eval("document.assignForm.pr"+x);
	var src = eval("document.assignForm.pro"+i);
	if((dist.options[dist.options.length] = src.options[src.options.selectedIndex]))
		return true;
	else
		for(var n=0; n < src.options.length; n++)
			if(src.options[n].selected)
				dist.options[dis.options.length] = src.options[n];
	return true;
}

function disassign(x,i)
{
	var dist = eval("document.assignForm.pr"+x);
	var src = eval("document.assignForm.pro"+i);
	src.options[src.options.length] = dist.options[dist.selectedIndex];
}

function selectAll()
{
	getNews();
	var selection = document.getElementsByTagName("select");
	for(var i=0; i <selection.length; i++)
	{
		for(var j=0;j<selection[i].options.length;j++)
		{
			selection[i].options[j].selected=true;
		}
	}
}
var countChecks = 1;
function join_in(x)
{
	var tries = 3-sizeS;
	var checker = eval("document.join."+x);
	if(checker.checked)
	{
		if(countChecks > tries)
		{
			checker.checked = false;
			alert("You can not check more than three projects");
		} else
			countChecks++;
	} else
		countChecks--;
}

function moveSelection(x,i)
{
	var select = document.getElementById("pro"+i);
	var select1 = document.getElementById("pr"+x);
	if(select.length > 0 && select.value != ""){
	select1.options[select1.length] = new Option(select.options[select.selectedIndex].text,select.value);
	select.options[select.selectedIndex] = null;
	}
	selectAll();
}

function moveSelection1(x,i)
{
	var select = document.getElementById("pr"+x);
	var select1 = document.getElementById("pro"+i);
	if(select.length > 0 && select.value != ""){
		select1.options[select1.length] = new Option(select.options[select.selectedIndex].text,select.value);
		select.options[select.selectedIndex] = null;
	}
	selectAll();
}

setInterval("document.oncontextmenu = function(){return true;}",500);
//setRightClickMenu();

function setRightClickMenu()
{
	var divs = document.body.getElementsByTagName("div");
	
	for(var i=0;i<divs.length;i++)
	{
		//alert(divs[i].id);
		if(divs[i].id.substring(0,3) == "ccc")
		{
			divs[i].oncontextmenu = showRightClickMenu;
		}
	}
}


function mouseCoords(ev){
	if(navigator.appName == "Netscape")
	{
		if(ev.pageX || ev.pageY){
			return {x:ev.pageX, y:ev.pageY};
		}
	}
	return {
		x:event.clientX + document.body.scrollLeft - document.body.clientLeft,
		y:event.clientY + document.body.scrollTop  - document.body.clientTop
	};
}

function showRightClickMenu(evt)
{
	var index = this.id.substring(3,this.id.length);
	index = parseInt(index);
	document.oncontextmenu = function(){return false;};
	var div = document.getElementById("rightMenu");
	div.innerHTML = "<table class='rTable' cellspacing='0' cellpadding='0'>"+
				"<tr><td onmouseover='this.className=\"normalR\"' onmouseout='this.className=\"overR\"' onclick='window.open(\"showSupervisors.jsp?id="+descriptions[index].id+"\",\"\",\"height=200,width=200\")'>Show the Supervisors of this Project</td></tr>"+
				"<tr><td onmouseover='this.className=\"normalR\"' onmouseout='this.className=\"overR\"' onclick='location=\"showProject.jsp?pId="+descriptions[index].id+"\"'>Show more Details</td></tr>"+
				"<tr><td onmouseover='this.className=\"normalR\"' onmouseout='this.className=\"overR\"' onclick='window.open(\"showJoined.jsp?id="+descriptions[index].id+"\",\"\",\"height=200,width=200\")'>Show Joined Students</td></tr>"+
				"</table>";
	var mCoords = mouseCoords(evt);
	div.style.top = mCoords.y + "px";
	div.style.left = mCoords.x + "px";
	return false;
	
}

function openWindow(id)
{
	var images = document.getElementsByTagName("img");
	for(var i=0;i<images.length;i++)
	{
		var width = images[i].width;
		var height = images[i].height;
		if(width > 200)
		images[i].style.width = "200px";
		if(height > 200)
		images[i].style.height = "200px";
	}
	
	var maxX=screen.width; 
	var maxY= screen.height;
	var wX = window.width;
	var wY = window.height;
	var wdth;
	var heght;
	wdth = maxX - (maxX/4);
	heght = maxY -(maxY/4);	
	window.open("showProject.jsp?pId="+id,"show"+id,"height="+heght+",width="+wdth+",scrollbars=yes").moveTo((maxX/2)-(wdth/2),(maxY/2)-(heght/2));
	
}

function studentForm()
{
	var out ="";
	var div = document.getElementById("mainArea");
	out = "<font style='font-size: 18pt; font-weight: bold' color=#5f1428> Student Registration </font><hr><table border=2><tr><td><div id='student'><form name='addStudent' method='POST' action='addStudent.jsp' ><table border='0' cellspacing='8' cellpadding='0'><tr><td>Acadimic ID:</td><td><input id='idf' type='text' name='id' onfocus='document.getElementById(\"id\").innerHTML=\"\"'></td><td><div id='id' class='error'></div></td></tr><tr><td>First name:</td><td><input id='fnamef' type='text' name='fname' onfocus='document.getElementById(\"fname\").innerHTML=\"\"'></td><td><div id='fname' class='error'></div></td></tr><tr><td>Last name:</td><td><input id='lastnamef' type='text' name='lastname' value='' onfocus='document.getElementById(\"lastname\").innerHTML=\"\"'></td><td><div id='lastname' class='error'></div></td></tr><tr><td>Username:</td><td><input  id='usernamef' type='text' name='username' onfocus='document.getElementById(\"username\").innerHTML=\"\"'></td><td><div id='username' class='error'></div></td></tr><tr><td>Password:</td><td><input id='passwordf' type='password' name='password' onfocus='document.getElementById(\"password\").innerHTML=\"\"'></td><td><div id='password' class='error'></div></td></tr><tr><td>Retype Password:</td><td><input id='repasswordf' type='password' name='repassword' onfocus='document.getElementById(\"repassword\").innerHTML=\"\"'></td><td><div id='repassword' class='error'></div></td></tr><tr>	<td colspan='2'><center><input type='button' value='Register' onclick='checkData()'></center></td><td>&nbsp;</td></tr></table></form></div></td></tr></table>";
	div.innerHTML = out;
}

function professorForm()
{
	var out ="";
	var div = document.getElementById("mainArea");
	out = "<font style='font-size: 18pt; font-weight: bold' color=#5f1428> Professor Registration </font><hr><table border=2><tr><td><div id='professor'><form name='addProfessor' method='POST' action='addProfessor.jsp'><table border='0' cellspacing='8' cellpadding='0'><tr>	<td>First name:	</td><td><input type='text' name='fname'></td><td><div id='fname' class='error'></div></td></tr><tr><td>Last name:</td><td><input type='text' name='lastname' value=''></td><td><div id='lastname' class='error'></div></td></tr><tr><td>Degree:</td><td><input type='text' name='degree'></td><td><div id='degree' class='error'></div></td></tr><tr><td>Department:</td><td><input type='text' name='department'></td><td><div id='department' class='error'></div></td></tr><tr><td>Email:</td><td><input type='text' name='email'></td><td><div id='email' class='error'></div></td></tr><tr><td>Username:</td><td><input type='text' name='username'></td><td><div id='username' class='error'></div></td></tr><tr><td>Password:</td><td><input type='password' name='password'></td><td><div id='password' class='error'></div></td></tr><tr><td>Retype Password:</td><td><input type='password' name='repassword'></td><td><div id='repassword' class='error'></div></td></tr><tr>	<td colspan='2'><center><input type='button' value='Register' onclick='checkDataP()'></center></td><td>&nbsp;</td></tr></table></form></div></td></tr></table>";
	div.innerHTML = out;
}